home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / telecom / 96 / c / fseldemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-15  |  11.1 KB  |  355 lines

  1.  
  2. /*********************************************************************/
  3. /* SAMPLE APPLICATION SKELETON                                  */
  4. /*    started 5/28/85 R.Z.   Copyright ATARI Corp. 1985         */
  5. /*                                                             */
  6. /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv  */
  7. /*                                                               */
  8. /* Used to build demonstrator for new FSEL function          */
  9. /* Modified by D. N. Korte  (bix dnkorte)  26 Dec 86         */
  10. /*                                                           */
  11. /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
  12. /*********************************************************************/
  13.  
  14. /*********************************************************************/
  15. /* INCLUDE FILES                             */
  16. /*********************************************************************/
  17.  
  18. #include <obdefs.h>
  19. #include <gemdefs.h>
  20. #include <osbind.h>
  21.  
  22. /*********************************************************************/
  23. /* DEFINES                                    */
  24. /*********************************************************************/
  25.  
  26. #define TRUE 1
  27. #define FALSE 0
  28. #define WI_KIND        (SIZER|MOVER|FULLER|CLOSER|NAME)
  29.  
  30. #define NO_WINDOW (-1)
  31.  
  32. #define MIN_WIDTH  (2*gl_wbox)
  33. #define MIN_HEIGHT (3*gl_hbox)
  34.  
  35. /*********************************************************************/
  36. /* EXTERNALS                                    */
  37. /*********************************************************************/
  38.  
  39. extern int    gl_apid;
  40.  
  41. /*********************************************************************/
  42. /* GLOBAL VARIABLES                                */
  43. /*********************************************************************/
  44.  
  45. int    gl_hchar;
  46. int    gl_wchar;
  47. int    gl_wbox;
  48. int    gl_hbox;                    /* system sizes */
  49.  
  50. int     phys_handle;            /* physical workstation handle */
  51. int     handle;                    /* virtual workstation handle */
  52. int    wi_handle;                    /* window handle */
  53. int    top_window;                    /* handle of topped window */
  54.  
  55. int    xdesk,ydesk,hdesk,wdesk;
  56. int    xold,yold,hold,wold;
  57. int    xwork,ywork,hwork,wwork;    /* desktop and work areas */
  58.  
  59. int    msgbuff[8];                    /* event message buffer */
  60. int    keycode;                    /* keycode returned by event-keyboard */
  61. int    mx,my;                        /* mouse x and y pos. */
  62. int    butdown;                    /* button state tested for, UP/DOWN */
  63. int    ret;                        /* dummy return variable */
  64.  
  65. int    hidden;                        /* current state of cursor */
  66.  
  67. int    fulled;                        /* current state of window */
  68.  
  69. int    contrl[12];
  70. int    intin[128];
  71. int    ptsin[128];
  72. int    intout[128];
  73. int    ptsout[128];                /* storage wasted for idiotic bindings */
  74.  
  75. int work_in[11];    /* Input to GSX parameter array */
  76. int work_out[57];    /* Output from GSX parameter array */
  77. int pxyarray[10];    /* input point array */
  78.  
  79. /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
  80. /* Global variables relevant to FSEL demonstration                         */
  81. int  sextn,              /* bitmap for extension selection                 */
  82.      driv,               /* drive selector                                 */
  83.      stat;               /* fsel return status                             */
  84. char extn3[4],extn4[4],  /* "editable" extension text                     */
  85.      path[256],          /* directory path, sans drive, with \...\         */
  86.      fullname[256];      /* full name with drive, path, name.extn         */
  87. /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ 
  88.  
  89. /****************************************************************/
  90. /*  GSX UTILITY ROUTINES.                    */
  91. /****************************************************************/
  92.  
  93. hide_mouse()
  94. {
  95.     if(! hidden){
  96.         graf_mouse(M_OFF,0x0L);
  97.         hidden=TRUE;
  98.     }
  99. }
  100.  
  101. show_mouse()
  102. {
  103.     if(hidden){
  104.         graf_mouse(M_ON,0x0L);
  105.         hidden=FALSE;
  106.     }
  107. }
  108.  
  109. /****************************************************************/
  110. /* open virtual workstation                    */
  111. /****************************************************************/
  112. open_vwork()
  113. {
  114. int i;
  115.     for(i=0;i<10;work_in[i++]=1);
  116.     work_in[10]=2;
  117.     handle=phys_handle;
  118.     v_opnvwk(work_in,&handle,work_out);
  119. }
  120.  
  121. /****************************************************************/
  122. /* set clipping rectangle                    */
  123. /****************************************************************/
  124. set_clip(x,y,w,h)
  125. int x,y,w,h;
  126. {
  127. int clip[4];
  128.     clip[0]=x;
  129.     clip[1]=y;
  130.     clip[2]=x+w;
  131.     clip[3]=y+h;
  132.     vs_clip(handle,1,clip);
  133. }
  134.  
  135. /****************************************************************/
  136. /* open window                            */
  137. /****************************************************************/
  138. open_window()
  139. {
  140.     wi_handle=wind_create(WI_KIND,xdesk,ydesk,wdesk,hdesk);
  141.     wind_set(wi_handle, WF_NAME," FSEL Demo ",0,0);
  142.     graf_growbox(xdesk+wdesk/2,ydesk+hdesk/2,gl_wbox,gl_hbox,xdesk,ydesk,wdesk,hdesk);
  143.     wind_open(wi_handle,xdesk,ydesk,310,100);
  144.     wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
  145. }
  146.  
  147. /****************************************************************/
  148. /* find and redraw all clipping rectangles            */
  149. /****************************************************************/
  150. do_redraw(xc,yc,wc,hc)
  151. int xc,yc,wc,hc;
  152. GRECT t1,t2;
  153.  
  154.     hide_mouse();
  155.     wind_update(TRUE);
  156.     t2.g_x=xc;
  157.     t2.g_y=yc;
  158.     t2.g_w=wc;
  159.     t2.g_h=hc;
  160.     wind_get(wi_handle,WF_FIRSTXYWH,&t1.g_x,&t1.g_y,&t1.g_w,&t1.g_h);
  161.     while (t1.g_w && t1.g_h) {
  162.       if (rc_intersect(&t2,&t1)) {                /* anybody know where rc_intersect is documented? */    
  163.         set_clip(t1.g_x,t1.g_y,t1.g_w,t1.g_h);    /* not in Abacus or Megamax docs as far as I can see... */
  164.         write_info();
  165.       }
  166.       wind_get(wi_handle,WF_NEXTXYWH,&t1.g_x,&t1.g_y,&t1.g_w,&t1.g_h);
  167.     }
  168.     wind_update(FALSE);
  169.     show_mouse();
  170. }
  171.  
  172. /****************************************************************/
  173. /*        Accessory Init. Until First Event_Multi        */
  174. /****************************************************************/
  175. main()
  176. {
  177.     appl_init();
  178.     phys_handle=graf_handle(&gl_wchar,&gl_hchar,&gl_wbox,&gl_hbox);
  179.     wind_get(0, WF_WORKXYWH, &xdesk, &ydesk, &wdesk, &hdesk);
  180.     open_vwork();
  181.         open_window();
  182.     graf_mouse(ARROW,0x0L);
  183.  
  184.     hidden=FALSE;
  185.     fulled=FALSE;
  186.     butdown=TRUE;
  187.  
  188. /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */
  189.     sextn = 0x03;         /* select extn0 and extn1                         */
  190.     driv  = -1;           /* ask for working drive                          */
  191.     strcpy(extn3,"   ");  /* no initial text for user-editable extensions     */
  192.     strcpy(extn4,"   ");  /* but must fill with spaces so it will edit        */
  193.     strcpy(path,"\\");    /* original path spec just starts at root         */
  194. /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
  195.  
  196.     multi(); 
  197. }
  198.  
  199.  
  200. /****************************************************************/
  201. /* dispatches all accessory tasks                */
  202. /****************************************************************/
  203. multi()
  204. {
  205. int event;
  206.  
  207.     do {      /* big loop processes events until window close message */
  208.  
  209.     event = evnt_multi(MU_MESAG | MU_BUTTON | MU_KEYBD,
  210.             1,1,butdown,
  211.             0,0,0,0,0,
  212.             0,0,0,0,0,
  213.             msgbuff,0,0,&mx,&my,&ret,&ret,&keycode,&ret);
  214.  
  215.     wind_update(TRUE);
  216.     wind_get(wi_handle,WF_TOP,&top_window,&ret,&ret,&ret); /* added */
  217.  
  218.     if (event & MU_MESAG)
  219.       switch (msgbuff[0]) {
  220.  
  221.       case WM_REDRAW:
  222.         do_redraw(msgbuff[4],msgbuff[5],msgbuff[6],msgbuff[7]);
  223.         break;
  224.  
  225.       case WM_NEWTOP:
  226.       case WM_TOPPED:
  227.         wind_set(wi_handle,WF_TOP,0,0,0,0);
  228.         break;
  229.  
  230.       case WM_SIZED:
  231.       case WM_MOVED:
  232.         if(msgbuff[6]<MIN_WIDTH)msgbuff[6]=MIN_WIDTH;
  233.         if(msgbuff[7]<MIN_HEIGHT)msgbuff[7]=MIN_HEIGHT;
  234.         wind_set(wi_handle,WF_CURRXYWH,msgbuff[4],msgbuff[5],msgbuff[6],msgbuff[7]);
  235.         wind_get(wi_handle,WF_WORKXYWH,&xwork,&ywork,&wwork,&hwork);
  236.         break;
  237.  
  238.       case WM_FULLED:
  239.         if(fulled){
  240.         wind_calc(WC_WORK,WI_KIND,xold,yold,wold,hold,
  241.                 &xwork,&ywork,&wwork,&hwork);
  242.         wind_set(wi_handle,WF_CURRXYWH,xold,yold,wold,hold);}
  243.         else{
  244.         wind_calc(WC_BORDER,WI_KIND,xwork,ywork,wwork,hwork,
  245.                 &xold,&yold,&wold,&hold);
  246.         wind_calc(WC_WORK,WI_KIND,xdesk,ydesk,wdesk,hdesk,
  247.                 &xwork,&ywork,&wwork,&hwork);
  248.         wind_set(wi_handle,WF_CURRXYWH,xdesk,ydesk,wdesk,hdesk);
  249.         }
  250.         fulled ^= TRUE;
  251.         break;
  252.  
  253.       } /* switch (msgbuff[0]) */
  254.  
  255.     if ((event & MU_BUTTON)&&(wi_handle == top_window))
  256.       if(butdown) butdown = FALSE;
  257.       else butdown = TRUE;
  258.  
  259.     /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  260.      * Note we call fsel from this event.  It is important to note
  261.      * that all five extension text strings must be 3 full characters,
  262.      * even if those characters are spaces... 
  263.      * It is also important that the 'driv' and 'sextn' are pointers,
  264.      * not actual integers!
  265.      * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
  266.     if(event & MU_KEYBD){
  267.        stat = fsel("Select a file to try it out...",
  268.                    path,&driv,&sextn,"PRG","T??","*  ",extn3,extn4,fullname);
  269.        set_clip(xwork,ywork,wwork,hwork);   /* clip full work area */
  270.        write_info();     /* to ensure that full window is rewritten */
  271.     }
  272.     
  273.     wind_update(FALSE);
  274.  
  275.       } while(!((event & MU_MESAG) && (msgbuff[0] == WM_CLOSED)));
  276.       /* end of big loop processing events until WM_CLOSED message */
  277.  
  278.       wind_close(wi_handle);
  279.       graf_shrinkbox(xwork+wwork/2,ywork+hwork/2,gl_wbox,gl_hbox,xwork,ywork,wwork,hwork);
  280.       wind_delete(wi_handle);
  281.       v_clsvwk(handle);
  282.       appl_exit();
  283.  
  284. }
  285.  
  286. /****************************************************************/
  287. /*  fill window with info from called function                    */
  288. /*  This part just displays for the user what fsel() returned.  */
  289. /****************************************************************/
  290. write_info()
  291. {
  292. int  temp[4],vpos;
  293. char string[80],drivc,stats[6];
  294.     vsf_interior(handle,2);         /* fill style solid */
  295.     vsf_style(handle,8);            /* sort of the same, only more */
  296.     vsf_color(handle,WHITE);        /* fill with white when filling */
  297.     temp[0]=xwork;
  298.     temp[1]=ywork;
  299.     temp[2]=xwork+wwork-1;
  300.     temp[3]=ywork+hwork-1;
  301.     v_bar(handle,temp);                   /* blank the interior */
  302.     
  303.     vpos = ywork + 1* gl_hchar;     /* vertical position inside window */
  304.     sprintf(string,"Sextn: %2x",sextn);
  305.     v_gtext(handle,xwork,vpos,string);
  306.  
  307.     switch (driv) {
  308.         case 0: drivc = 'A'; break;
  309.         case 1: drivc = 'B'; break;
  310.         case 2: drivc = 'C'; break;
  311.         case 3: drivc = 'D'; break;
  312.         case 4: drivc = 'E'; break;
  313.         case 5: drivc = 'F'; break;
  314.         default:drivc = '?';
  315.     };
  316.     vpos += gl_hchar;               /* move down a line */
  317.     sprintf(string,"Drive: %2d (%c)",driv,drivc);
  318.     v_gtext(handle,xwork,vpos,string);
  319.  
  320.     vpos += gl_hchar;
  321.     sprintf(string,"extn3: %-4s",extn3);
  322.     v_gtext(handle,xwork,vpos,string);
  323.  
  324.     vpos += gl_hchar;
  325.     sprintf(string,"extn4: %-4s",extn4);
  326.     v_gtext(handle,xwork,vpos,string);
  327.  
  328.     vpos += gl_hchar;
  329.     sprintf(string,"path: %-16s",path);
  330.     v_gtext(handle,xwork,vpos,string);
  331.  
  332.     vpos += gl_hchar;
  333.     sprintf(string,"file: %-24s",fullname);
  334.     v_gtext(handle,xwork,vpos,string);
  335.  
  336.     switch (stat) {
  337.         case (0): strcpy(stats,"CANC"); break;
  338.         case (1): strcpy(stats,"OK");   break;
  339.         case (2): strcpy(stats,"ERROR");break;
  340.         default : strcpy(stats,"?????");
  341.     };
  342.     vpos += gl_hchar;
  343.     sprintf(string,"stat: %2d (%-5s)",stat,stats);
  344.     v_gtext(handle,xwork,vpos,string);
  345.  
  346.     vpos += gl_hchar;
  347. /*    vst_color(handle,RED);   */
  348.     v_gtext(handle,xwork,vpos,"Strike any key to select file");
  349.     
  350.     vpos += gl_hchar;
  351.     v_gtext(handle,xwork,vpos,"(or CLOSE this window to quit)");
  352. /*    vst_color(handle,BLACK); */
  353. }
  354.